﻿using System.Reactive;
using Avalonia.Controls;
using chen_bot_ui.Views;
using ReactiveUI;

namespace chen_bot_ui.ViewModels
{
    public class MainWindowViewModel : ViewModelBase
    {
        public BotControlViewModel BotControl { get; private set; } = new();
        public ChatViewModel ChatControl { get; private set; } = new();

        public ReactiveCommand<Unit, Unit> ExtendCommand { get; }

        private string _extendCommandContent;
        private bool _extendCommandVisible;
        private GridLength _extendCommandWidth;

        public string ExtendCommandContent
        {
            get => _extendCommandContent;
            set => this.RaiseAndSetIfChanged(ref _extendCommandContent, value);
        }

        public bool ExtendCommandVisible
        {
            get => _extendCommandVisible;
            set => this.RaiseAndSetIfChanged(ref _extendCommandVisible, value);
        }

        public GridLength ExtendCommandWidth
        {
            get => _extendCommandWidth;
            set => this.RaiseAndSetIfChanged(ref _extendCommandWidth, value);
        }

        public MainWindowViewModel()
        {
            _extendCommandContent = "<";
            _extendCommandVisible = false;
            _extendCommandWidth = GridLength.Auto;
            ExtendCommand = ReactiveCommand.Create(() =>
            {
                if (ExtendCommandContent == ">")
                {
                    ExtendCommandContent = "<";
                    ExtendCommandVisible = false;
                    ExtendCommandWidth = GridLength.Auto;
                }
                else
                {
                    ExtendCommandContent = ">";
                    ExtendCommandVisible = true;
                    ExtendCommandWidth = new GridLength(2, GridUnitType.Star);
                }
            });

        }
    }
}